package com.wodsy.phoenix.dataobject.shopc.model;

// Generated 2015-4-15 10:53:09 by Hibernate Tools 3.4.0.CR1

import com.wodsy.phoenix.dataobject.base.PhoenixObject;
import com.wodsy.phoenix.dataobject.base.PhoenixRequest;
import com.wodsy.phoenix.dataobject.base.PhoenixResponse;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Set;
import javax.persistence.*;

import static javax.persistence.GenerationType.IDENTITY;

/**
 * TbFreightTemp generated by hbm2java
 */
@Entity
@Table(name = "tb_freight_temp", catalog = "shopc")
public class FreightTemp extends PhoenixObject implements Serializable,PhoenixRequest,PhoenixResponse {

    private Integer id;
    private int userId;
    private int shopId;
    private String name;
    private String shipmentsOrigin;
    private boolean isFree = false;
    private FreightTempPriceUnit priceUnit;
    private boolean isEnable = true;
    private Set<FreightTempSub> freightTempSubs;
    private Date addTime;
    private Date updateTime;

    public FreightTemp() {
    }


    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "id", unique = true, nullable = false)
    public Integer getId() {
        return this.id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Column(name = "user_id", nullable = false)
    public int getUserId() {
        return this.userId;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }

    @Column(name = "shop_id", nullable = false)
    public int getShopId() {
        return this.shopId;
    }

    public void setShopId(int shopId) {
        this.shopId = shopId;
    }

    @Column(name = "name", nullable = false)
    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Column(name = "shipments_origin", length = 40)
    public String getShipmentsOrigin() {
        return this.shipmentsOrigin;
    }

    public void setShipmentsOrigin(String shipmentsOrigin) {
        this.shipmentsOrigin = shipmentsOrigin;
    }

    @Column(name = "is_free")
    public boolean getIsFree() {
        return this.isFree;
    }

    public void setIsFree(boolean isFree) {
        this.isFree = isFree;
    }

    @ManyToOne(cascade = CascadeType.REFRESH, fetch = FetchType.EAGER,targetEntity = FreightTempPriceUnit.class)
    @JoinColumn(name = "price_unit")
    public FreightTempPriceUnit getPriceUnit() {
        return this.priceUnit;
    }

    public void setPriceUnit(FreightTempPriceUnit priceUnit) {
        this.priceUnit = priceUnit;
    }

    @OneToMany(fetch = FetchType.EAGER, targetEntity = FreightTempSub.class, cascade = {CascadeType.ALL},orphanRemoval = true)
    @JoinColumns(value = {@JoinColumn(name = "ft_id", referencedColumnName = "id")})
    public Set<FreightTempSub> getFreightTempSubs() {
        return freightTempSubs;
    }

    public void setFreightTempSubs(Set<FreightTempSub> freightTempSubs) {
        this.freightTempSubs = freightTempSubs;
    }

    public void addFreightTempSubs(Set<FreightTempSub> freightTempSubs) {
        if(this.freightTempSubs != null){
            this.freightTempSubs.clear();
            if (freightTempSubs != null && !freightTempSubs.isEmpty()) {
                this.freightTempSubs.addAll(freightTempSubs);
            }
        }else {
            this.freightTempSubs = freightTempSubs;
        }
    }

    @Column(name = "is_enable",nullable = false,columnDefinition = "tinyint(1) default 1")
    public boolean isIsEnable() {
        return this.isEnable;
    }

    public void setIsEnable(boolean isEnable) {
        this.isEnable = isEnable;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "add_time", nullable = false, length = 19)
    public Date getAddTime() {
        return this.addTime;
    }

    public void setAddTime(Date addTime) {
        this.addTime = addTime;
    }

    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "update_time", length = 19)
    public Date getUpdateTime() {
        return this.updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    @Override
    public String toString() {
        return "FreightTemp{" +
                "id=" + id +
                ", userId=" + userId +
                ", shopId=" + shopId +
                ", name='" + name + '\'' +
                ", shipmentsOrigin='" + shipmentsOrigin + '\'' +
                ", isFree=" + isFree +
                ", priceUnit=" + priceUnit +
                ", isEnable=" + isEnable +
                ", freightTempSubs=" + freightTempSubs +
                ", addTime=" + addTime +
                ", updateTime=" + updateTime +
                '}';
    }
}
